#ifndef GLOBAL_H
#define GLOBAL_H

// Some global values
#define NUM_PROCS		10
#define STACK_SIZE		1024	// 2048 bytes, 2KB
#define NUM_FILE_DESC	10
#define PROCESS_RUNTIME	300

// Available process status's
#define DEAD	0
#define FREE	1
#define READY	2
#define SLEEP	3
#define ZOMBIE	4
#define BLOCK	5

// File modes
#define READ		0
#define WRITE		1
#define READ_PIPE	2
#define WRITE_PIPE	3

// Pipe values
#define PIPE_SIZE	10
#define NUM_PIPES	10
#define PIPE_FREE	0
#define PIPE_USED	1

// Define some new primitive types
typedef char			s8;
typedef unsigned char	u8;
typedef short			s16;
typedef unsigned short	u16;
typedef long			s32;
typedef unsigned long	u32;

// Create a bool type for C
typedef enum boolean
{
	false = 0, true
} bool;

// Pipe structure
typedef struct pipe
{
	char buf[PIPE_SIZE];
	int head, tail, data, room;
	int numReader, numWriter;
	int status;
} Pipe;

// File table entry
typedef struct file
{
	int mode;
	int refCount;
	Pipe* pipePtr;
} File;

// This is the process structure for the kernel
typedef struct process
{
	struct process* next;
	int	stackPointer;
	int userStackSegment;
	int userStackPointer;
	int	processID;
	int	parentProcessID;
	int	status;
	int	priority;
	int	event;
	int	exitValue;
	int	numChildren;
	int time;
	char name[20];
	char* deathCry;
	File* fileDescriptors[NUM_FILE_DESC];
	s16	stack[STACK_SIZE];
} Process;

typedef enum textColor
{
	BLACK = 0, BLUE, GREEN, CYAN, RED, PURPLE, YELLOW, WHITE,
	HBLACK, HBLUE, HGREEN, HCYAN, HRED, HPURPLE, HYELLOW, HWHITE
} TextColor;
extern TextColor color;

// Queue structure for managing processes
typedef struct processQueue
{
	Process*	top;
	int			size;
} ProcessQueue;

typedef struct semaphore
{
	int value;
	Process* queue;
} Semaphore;

// Global process structures
extern Process	processes[NUM_PROCS];
extern Process*	running;
extern ProcessQueue readyQueue;
extern ProcessQueue freeQueue;
extern ProcessQueue sleepQueue;
extern int processSize;
extern Pipe pipes[NUM_PIPES];
extern File fileEntries[NUM_FILE_DESC];
extern int inkmode;

extern void thandler();
extern void kbhandler();

// INT80 function
extern void int80h();
extern void goUmode();

#endif
